Skip to content

refactor(errors): standardize unknown-error normalization across the repository (#238) - #353

Draft
s6pa1rta3n-lab wants to merge 1 commit into
Sub-Rosa-Issue:mainfrom
s6pa1rta3n-lab:fix-issue-238
Draft

refactor(errors): standardize unknown-error normalization across the repository (#238)#353
s6pa1rta3n-lab wants to merge 1 commit into
Sub-Rosa-Issue:mainfrom
s6pa1rta3n-lab:fix-issue-238

Conversation

@s6pa1rta3n-lab

Copy link
Copy Markdown
Contributor

Summary

Resolves #238.

Standardizes unknown-error handling and normalization across all workspace packages, background services, and the web application.

Key Deliverables

  • Created @sub-rosa/errors package with dual ESM/CJS exports and tree-shaking support:
    • normalizeError: Converts any thrown unknown value (Error instances, thrown primitives, plain objects, nested causes, circular structures) into a strongly typed NormalizedError.
    • getErrorMessage and getPublicErrorMessage: Provide safe message extraction with secret scrubbing and actionable user guidance for Soroban contract codes.
    • Secret redaction: Recursively redacts bearer tokens, Stellar secret keys, PEM private keys, URL credentials, and sensitive property keys.
    • Test suite: 39 unit tests validating classification, normalization, snapshot-free assertable models, and redaction.
  • Added repository guard scripts/check-error-normalization.mjs and test suite scripts/check-error-normalization.test.mjs:
    • Enforces uniform error handling across packages/, services/, and apps/.
    • Blocks antipatterns such as unnormalized instanceof Error ternaries and raw String(e) coercions.
    • Configured root scripts errors-pkg:test, errors-pkg:typecheck, errors:guard, and errors:guard:test.
  • Migrated error handling call sites:
    • packages/sdk: preflight.ts, mainnet-readiness.ts.
    • packages/tlock: auditor-recovery-cli.ts.
    • services/keeper: queue.ts, keeper.ts, status.ts, watch-loop.ts, status-server.ts.
    • services/appraisal-api: server.ts.
    • services/receipt-cli: index.ts.
    • apps/web: chain.ts, demoActions.ts, useLiveRound.ts, useDrandCountdown.ts, useRoundSession.ts, useDashboardData.ts, PasskeyPanel.tsx, AuditorView.tsx, AttackDemo.tsx.
  • Integrated with repository weighted line coverage gate (89.53% coverage on @sub-rosa/errors).

Verification

  • pnpm errors-pkg:test (39 tests pass)
  • pnpm errors-pkg:typecheck (clean)
  • pnpm errors:guard (0 violations)
  • pnpm errors:guard:test (5 tests pass)
  • pnpm sdk:test (211 tests pass)
  • pnpm sdk:typecheck (clean)
  • pnpm tlock:test (67 tests pass)
  • pnpm tlock:typecheck (clean)
  • pnpm keeper:test (73 tests pass)
  • pnpm keeper:typecheck (clean)
  • pnpm appraisal:test (49 tests pass)
  • pnpm appraisal:typecheck (clean)
  • pnpm receipt-cli:test (19 tests pass)
  • pnpm receipt-cli:typecheck (clean)
  • pnpm web:test (81 tests pass)
  • pnpm web:typecheck (clean)
  • pnpm coverage:test (79.57% weighted coverage vs 70.00% gate, passed)

Payout Routing

  • EVM (Base/Arbitrum/Polygon/ETH): 0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89
  • Stellar: GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC

…repository

- Add @sub-rosa/errors package with normalizeError, getErrorMessage, redaction, and classification
- Add static analysis guard scripts/check-error-normalization.mjs to enforce consistent error handling
- Migrate error handling call sites across packages, services, and web app to standard normalization
- Enforce weighted test coverage across all error normalization paths

Closes Sub-Rosa-Issue#238
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(errors): standardize unknown-error normalization across the repository

1 participant